package com.dopios.services.webapp.controller;


import com.dopios.services.persistance.domain.CityAdvice;
import com.dopios.services.webapp.service.AdviceService;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.support.ReloadableResourceBundleMessageSource;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;

@Controller
@RequestMapping(value = "/submit")
public class AdviceAggregatorController {

    private static final Logger logger = Logger.getLogger(AdviceAggregatorController.class);

    @Autowired
    @Qualifier("adviceService")
    AdviceService adviceService;


    /*The rest API method that adds a new advice for a specific city by an authenticated user*/
    @RequestMapping(value = "advice/{user}/{city}/{adviceString}", method = RequestMethod.POST)
    public
    @ResponseBody
    String postCityAdvice(@PathVariable String user, @PathVariable String city, @PathVariable String adviceString) {
        logger.info(" User:" + user + " City:" + city + " Advice:" + adviceString);
        CityAdvice cityAdvice = new CityAdvice();
        cityAdvice.setAdvice(adviceString);
        cityAdvice.setCityName(city);
        cityAdvice.setUserAddedId(user);
        cityAdvice.setDateCreated(new Date());
        return adviceService.handleCityAdvice(cityAdvice);

    }

}
